<script setup lang='ts'>
  import { onMounted, reactive } from 'vue';
  import { statisticsApi } from '@/api/controller';
  import { Toastloading } from '@/utils/public';
  import { getPlayEndTime, getDateArray, parseTime } from '@/utils'
  import Pagination from "@/components/Pagination/index.vue";
  const action = reactive({
    total:0,
    list:[] as any[],
    dateArr:getDateArray('ymdhis') as Array<any>
  })
  const listQuery = reactive({
    page: 1,
    room_id:'',
    limit: 20,
  })
  const handleFilter = ()=>{
    listQuery.page = 1
    getList()
  }
  const filtersStatus = (status = -1)=>{
    return ['进行中','正常结束','提前关闭'][status] || ''
  }
  const resetQuery = ()=>{
    Object.assign(listQuery,{
      page:1,
      room_id:'',
      limit:20,
    })
    action.dateArr = getDateArray('ymdhis') as Array<any>
    getList()
  }
  const getList = async()=> {
    const loading = Toastloading()
    const timeObi = getPlayEndTime(action.dateArr)
    const res = await statisticsApi.roomPkList({
      ...listQuery,
      created_st:timeObi.playTime,
      created_ed:timeObi.endTime
    })
    loading.close()
    const { data=[], total=0 } = res.data
    action.list = data
    action.total = total
  }
  onMounted(()=>{
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">房间ID：</div>
          <el-input v-model="listQuery.room_id" placeholder="请输入房间ID" style="width: 160px" />
        </div>
        <div class="labelItem">
          <div class="label">日期：</div>
          <el-date-picker
            v-model="action.dateArr"
            type="datetimerange"
            format="YYYY-MM-DD HH:mm:ss"
            value-format="YYYY-MM-DD HH:mm:ss"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          />
        </div>
        <div class="labelItem">
          <el-button type="primary" @click="handleFilter">查询</el-button>
          <el-button type="primary" @click="resetQuery">重置</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column width="120" prop="id" label="ID" />
      <el-table-column width="120" prop="room_id" label="房间ID" />
      <el-table-column width="120" prop="roomName" label="房间名称" />
      <el-table-column width="120" prop="user_id" label="主持用户ID" />
      <el-table-column width="120" prop="team_name_1" label="队伍1名称" />
      <el-table-column width="120" sortable prop="team_score_1" label="队伍1积分"/>
      <el-table-column width="120" prop="team_name_2" label="队伍2名称" />
      <el-table-column width="120" sortable prop="team_score_2" label="队伍2积分"/>

      <el-table-column width="180" prop="battle_start_at" label="开始时间（秒）">
        <template #default="scoped">
          {{ parseTime(scoped.row.battle_start_at) }}
        </template>
      </el-table-column>
      <el-table-column width="180" prop="battle_end_at" label="计划结束时间（秒）">
        <template #default="scoped">
          {{ parseTime(scoped.row.battle_end_at) }}
        </template>
      </el-table-column>
      <el-table-column width="120" prop="battle_duration" label="团战时间（秒）" />
      <el-table-column width="120" prop="true_battle_duration" label="真实团战时间（秒）" />
      <el-table-column width="120" sortable prop="micro_user_num" label="结束时的在麦人数" />
      <el-table-column width="120" prop="status" label="结束类型">
        <template #default="scoped">
          {{ filtersStatus(scoped.row.status) }}
        </template>
      </el-table-column>

    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
  </div>
</template>